package cn.zy._03.single;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Producer {
    public static void main(String[] args) throws Exception {
        // 实例化消息生产者Producer
        DefaultMQProducer mqProducer = new DefaultMQProducer("hello-producer-group");
        // 设置NameServer的地址
        mqProducer.setNamesrvAddr("localhost:9876");
        // 启动Producer实例
        mqProducer.start();

        // 创建消息1，并指定Topic，Tag和消息体
        Message message = new Message("hello-topic3", "hello-tags3", "远坂凛".getBytes(RemotingHelper.DEFAULT_CHARSET));
        mqProducer.sendOneway(message);

        // 如果不再发送消息，关闭Producer实例
        mqProducer.shutdown();
    }
}